import server from './http.js' //导入axios
// 登录模块
const getLogin = (msg) => {
    let data = server.post('/login', msg)
    return data
}
//左侧导航
const menusList = () => {
    let data = server.get('/menus')
    return data
}

// 用户模块
//用户列表
const userlist = (params) => {
    // let data =  server.get('/users', {params:params})
    let data = server.get('/users', { params })
    return data
}

const delUser = (id) => {
    let data = server.delete("users/" + id)
    return data
}

const editUsers = (id, params) => {
    let data = server.put("users/" + id, params)
    return data
}

const changeStatus = (id, type) => {
    let data = server.put(`users/${id}/state/${type}`)
    return data
}


const addUsers = (params) => {
    let data = server.post("users", params)
    return data
}

const getRoles = () => {
    let data = server.get("roles")
    return data
}

const addRoles = (params) => {
    let data = server.post("roles", params)
    return data
}

const delRoles = (id) => {
    let data = server.delete("roles/" + id)
    return data
}

const editRoles = (id, params) => {
    let data = server.put("roles/" + id, params)
    return data
}

const Rights = (type) => {
    let data = server.get("rights/" + type)
    return data
}

const Goods = (params) => {
    let data = server.get(`goods`, { params })
    return data
}

const addGoods = (params) => {
    let data = server.post(`goods`,  params )
    return data
}

const delGoods = (id) => {
    let data = server.delete('goods/' + id)
    return data
}
//所有权限
const getrights = (type) => {
    let data = server.get('rights/' + type)
    return data
}

const addRight = (id, rids) => {
    let data = server.post(`roles/${id}/rights`, { rids: rids })
    return data
}


const updaterole = (msg) => {
    let data = server.post(`roles/${msg.id}/rights`, { rids: msg.rids })
    return data
}

const delRights = (id, rid) => {
    let data = server.delete(`roles/${id}/rights/${rid}`)
    return data
}

//商品分类
const categories = (abc) => {
    let data = server.get(`categories`, { params: abc })
    return data
}

//添加商品分类

const addcategories = (parmas) => {
    let data = server.post('categories', parmas)
    return data
}

//编辑分类
const editcategories = (id, parmas) => {
    let data = server.put(`categories/${id}`, parmas)
    return data
}

//删除分类
const delcategories = (id) => {
    let data = server.delete(`categories/${id}`)
    return data
}
//参数静动态列表
const goodcategories = (id, type) => {
    let data = server.get(`categories/${id}/attributes?sel=` + type)
    return data
}

const upcategories = (id, rid, params) => {
    let data =  server.put(`categories/${id}/attributes/${rid}`, params)
    return data
}

//添加动态参数或者静态属性
const addCate1 = (id,params) => {
    let data =  server.post(`categories/${id}/attributes`,params)
    return data
}
const delCate1 = (id,rid) => {
    let data =  server.delete(`categories/${id}/attributes/${rid}`,)
    return data
}

const getReports = () => {
    let data =  server.get("reports/type/1")
    return data
}

export {
    getLogin,getReports,delCate1,addGoods,addCate1,upcategories, goodcategories, delcategories, editcategories, addcategories, categories, delRights, addRight, updaterole, getrights, Rights, delGoods, Goods, addRoles, editRoles, delRoles, menusList, userlist, delUser, editUsers, changeStatus, addUsers, getRoles
}


//接口要命名规范,-获取数据getLogin,设置提交数据 setLogin,
//删除数据 delLogin,列表数据 loginList等